package android.support.v4.os;

import com.edroid.autorunner.um.UserManager;
import com.edroid.other.Custom;

/**
 * 
 * @author YYichou 2014-9-10
 *
 */
public class ESystem extends EHook {
	public static boolean hookTime = false;

	
	@Override
	public String getClassName() {
		return System.class.getName();
	}

	@Override
	public void hook() {
		findAndHookMethod("currentTimeMillis", this);
		findAndHookMethod("exit", int.class, this);
		counter = 0;
	}
	
	@Override
	protected boolean before(String name, Object[] args, MethodHookParam param) {
		
		if("exit".equals(name)) {
			log.d("System", "before " + name);

			UserManager.getInstance().onExit();
		}
		
		return super.before(name, args, param);
	}

	private static long counter;
	@Override
	protected void after(String name, Object[] args, MethodHookParam param) {
		if(Custom.hookTime && "currentTimeMillis".equals(name) && hookTime) {
//			param.setResult((Long)param.getResult() + Statics.appTime*1000);
			param.setResult((Long)param.getResult() + counter);
			counter += 100;
		//	Log.e("aaaaaaaaaa", "count= asdf +"+counter);
		}
	}
}
